<template>
  <div id="menu_id">
    <!-- 上层注释以及添加按钮 -->
    <div class="menu_id_top">
      <div class="menu_id_left">
        注：<br />
        1.增加的新栏目为当前栏目的下一行<br />
        2.修改完的栏目一行需要后提交审批才能生效
      </div>
      <div class="menu_id_right">
        <el-button round @click="add">增加</el-button>
      </div>
    </div>
    <!-- 下层渲染表格  -->
    <el-table
      :data="menuList"
      style="width: 100%; margin-bottom: 20px; margin-top: 20px"
      row-key="id"
      border
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="id" label="编号"> </el-table-column>
      <el-table-column prop="title" label="栏目名称"> </el-table-column>
      <el-table-column prop="icon" label="栏目图标" v-slot="$r">
        <template>
          <i :class="$r.row.icon"></i>
        </template>
      </el-table-column>
      <el-table-column prop="url" label="栏目地址"> </el-table-column>
      <el-table-column label="栏目状态" prop="status" v-slot="$s" width="155">
        <template>
          <el-button round size="mini" type="success" v-if="$s.row.status == 1">
            已启用
          </el-button>
        </template>
        <template>
          <el-button round size="mini" type="danger" v-if="$s.row.status == 0">
            已禁用
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作" v-slot="$shuju">
        <template>
          <el-button
            round
            class="xiugai"
            type="warning"
            @click="xiugai($shuju.row)"
            >修改</el-button
          >
        </template>
        <template>
          <el-button
            round
            class="shanchu"
            type="danger"
            @click="remoe($shuju.row.id)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <AddMenu
      :isshow="isshow"
      :menuList="menuList"
      @chongqi="chongqi"
      ref="xiugai_ref"
    ></AddMenu>
  </div>
</template>

<script>
import AddMenu from "./addmenu.vue";
import { mapActions, mapState } from "vuex";
export default {
  data() {
    return {
      isshow: { sta: false },
    };
  },
  created() {
    this.MenuActions();
  },
  computed: {
    ...mapState({ menuList: (state) => state.MenuStore.MenuList }),
  },
  methods: {
    // 点击增加的时候出现
    add() {
      this.isshow.sta = "true";
    },
    //点击修改的时候出现
    xiugai(obj) {
      this.isshow.sta = "true";
      this.$refs.xiugai_ref.xiugaiM(obj);
    },
    // 点击删除的时候出现
    remoe(id) {
      this.$confirm("此操作将永久删除该目录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$http.post("/api/menudelete", { id }).then((res) => {
            console.log(res);
            this.MenuActions();
          });
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    ...mapActions("MenuStore", ["MenuActions"]),
    chongqi() {
      this.MenuActions();
    },
  },
  components: {
    AddMenu,
  },
};
</script>

<style>
#menu_id .menu_id_top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#menu_id .menu_id_top .menu_id_left {
  font-size: 12px;
  color: #c4c4c4;
}
#menu_id .menu_id_top .menu_id_right button {
  height: 10px;
  line-height: 2px;
  font-size: 12px;
  color: #ffa998;
}
#menu_id .xiugai,
#menu_id .shanchu {
  height: 10px;
  line-height: 2px;
}
</style>